package cn.cnhis.online.mymodule;


import java.io.File;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;

public class HttpController {

    public static RetrofitService retrofitService;

    static {
        retrofitService = Api.getmServer();
    }


    /*登录*/
    public static void mobileLogin(Map<String, String> map, Observer<Map> observer) {
        setSubscribe(retrofitService.mobileLogin(map), observer);
    }

    /*获取验证码*/
    public static void getVerification(Map<String, String> map, Observer<ResponseBody> observer) {
        setSubscribe(retrofitService.getVerification(), observer);
    }


    /*获取logo*/
    public static void getLogo(Map<String, String> map, Observer<Map> observer) {
        setSubscribe(retrofitService.getLogo(), observer);
    }

    /*获取主题色*/
    public static void getMenuShowColor(Map<String, String> map, Observer<Map> observer) {
        setSubscribe(retrofitService.getMenuShowColor(), observer);
    }    /*获取主题色*/


    /*获取版本信息*/
    public static void getAppVersion(String version, Observer<Map> observer) {
        setSubscribe(retrofitService.getAppVersion(version), observer);
    }   /*获取版本信息*/

    /*获取MQ 配置信息*/
    public static void getAppActiveMqInfo(Map map, Observer<Map> observer) {
        setSubscribe(retrofitService.getAppActiveMqInfo(), observer);
    }
    /*上传文件*/
    public static void loadFile(List<MultipartBody.Part> parts, Observer<Map> observer) {
        setSubscribe(retrofitService.loadFile(parts), observer);
    }

    private static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
        observable.subscribeOn(Schedulers.io())
                .subscribeOn(Schedulers.newThread())//子线程访问网络
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .subscribe(observer);
    }


}
